#ifndef  __IDXMERGE_H_
#define  __IDXMERGE_H_

#include "common.h"
#include "logger.h"
#include "globals.h"
#include "termlist.h"
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#define MAX_MERGE_FILE	1024
#define MAX_IDX_NUM	100000000

class IdxMerger {
public:
  IdxMerger(){}
  ~IdxMerger(){}

  int merge(char* fname_pre, char* tofile_pre);
  int doit(char* fname);
private:
  int load_mmap(char* fname_pre);
  void deload();

  void add_to_list();
  int mov_to_next();

  //FILE* m_idx_fp[MAX_MERGE_FILE];
  int   m_idx_fnum;
  char* m_ptr[MAX_MERGE_FILE];
  int   m_fsize[MAX_MERGE_FILE];
  int   m_fd[MAX_MERGE_FILE];

  idx_head_t* mp_head[MAX_MERGE_FILE];
  idx_head_t* mt[MAX_MERGE_FILE];

  FILE* fp;
  char m_fname_pre[NAME_LEN];
  int  m_fid;
  uint32_t num_terms;
  uint32_t total_terms;

  idx_count_t* cbuff;
};














#endif  //__IDXMERGE_H_
